package com.guchenbo.example.html;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author guchenbo
 * @date 2020/11/2
 */
public class JsoupDemo {
    public static void main(String[] args) {
        String html = "<table class=\"table\">\n"
                        + "  <tbody>"
                        + "  <tr>\n"
                        + "    <td>file</td>\n"
                        + "    <td>File containing the application to execute</td>\n"
                        + "    <td>path (required)</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>proxyUser</td>\n"
                        + "    <td>User to impersonate when running the job</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>className</td>\n"
                        + "    <td>Application Java/Spark main class</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>args</td>\n"
                        + "    <td>Command line arguments for the application</td>\n"
                        + "    <td>list of strings</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>jars</td>\n"
                        + "    <td>jars to be used in this session</td>\n"
                        + "    <td>list of strings</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>pyFiles</td>\n"
                        + "    <td>Python files to be used in this session</td>\n"
                        + "    <td>list of strings</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>files</td>\n"
                        + "    <td>files to be used in this session</td>\n"
                        + "    <td>list of strings</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>driverMemory</td>\n"
                        + "    <td>Amount of memory to use for the driver process</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>driverCores</td>\n"
                        + "    <td>Number of cores to use for the driver process</td>\n"
                        + "    <td>int</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>executorMemory</td>\n"
                        + "    <td>Amount of memory to use per executor process</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>executorCores</td>\n"
                        + "    <td>Number of cores to use for each executor</td>\n"
                        + "    <td>int</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>numExecutors</td>\n"
                        + "    <td>Number of executors to launch for this session</td>\n"
                        + "    <td>int</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>archives</td>\n"
                        + "    <td>Archives to be used in this session</td>\n"
                        + "    <td>List of string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>queue</td>\n"
                        + "    <td>The name of the YARN queue to which submitted</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>name</td>\n"
                        + "    <td>The name of this session</td>\n"
                        + "    <td>string</td>\n"
                        + "  </tr>\n"
                        + "  <tr>\n"
                        + "    <td>conf</td>\n"
                        + "    <td>Spark configuration properties</td>\n"
                        + "    <td>Map of key=val</td>\n"
                        + "  </tr>\n"
                        + "</tbody></table>";
        Document doc = Jsoup.parse(html);

        Elements eles = doc.select("tbody > tr");
        System.out.println(eles.size());
        StringBuffer sb = new StringBuffer();


        for (Element ele : eles) {
            String txt = ele.select("td").get(0).text();

            sb.append("private String ").append(txt).append(";\n");
        }
        System.out.println(sb.toString());
    }
}
